package com.jfs.config;

import com.jfs.security.properties.SecurityProperties;
import com.jfs.security.resolver.LoginUserResolver;
import com.jfs.security.service.RoleService;
import com.jfs.security.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description web配置
 * @E-mail cwm3412638@163.com
 * @Author cwm
 * @Date 2022/8/8
 */
@Configuration
@AllArgsConstructor
public class WebConfig implements WebMvcConfigurer {
    private final SecurityProperties securityProperties;
    private final UserService userService;
    private final RoleService roleService;



    /**
     * 配置自定义loginUser户注解参数解析器
     * @param resolvers
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
        //添加消息转换器
        converters.add(new MappingJackson2HttpMessageConverter());
        //消息转换器与Resolver绑定
        resolvers.add(new LoginUserResolver(converters, securityProperties,userService,roleService));
    }


}
